unit u_input;


interface
 uses
  Microsoft.DirectX.DirectInput,
  Microsoft.DirectX,
  System.Windows.Forms,
  System.ComponentModel;
 type
  c_Input = Class
    public
      Key : Microsoft.DirectX.DirectInput.device;
      Mouse : Microsoft.DirectX.DirectInput.device;
      KeyState : KeyboardState;
      MouseState : MouseState;
      Constructor KeyandmouseCreate;
      procedure Dispose;
      procedure InitializeKeyboard(formctrl:control);
      procedure InitializeMouse(formctrl:control);
      Procedure Keybupdate;
      Procedure Mouseupdate;
  end;

implementation
 Constructor c_Input.KeyandmouseCreate;
  begin
    inherited Create;
    Key:= device.Create(SystemGuid.Keyboard);
    Mouse := Device.Create(SystemGuid.Mouse);
  end;

  procedure c_Input.InitializeKeyboard(formctrl:control);
  begin
    Key.SetCooperativeLevel(formctrl,CooperativeLevelFlags.NonExclusive or CooperativeLevelFlags.Background);
    key.SetDataFormat(DeviceDataFormat.Keyboard);
    Key.Acquire();

  end;

  procedure c_input.initializeMouse(formctrl:control);
  begin
    mouse.SetCooperativeLevel(formctrl,CooperativeLevelFlags.NonExclusive or CooperativeLevelFlags.Background);
    mouse.SetDataFormat(DeviceDataFormat.Mouse);
    mouse.Acquire();
  end;


  Procedure c_Input.Keybupdate;
  begin
    KeyState := Key.GetCurrentKeyboardState;
  end;

  Procedure c_input.Mouseupdate;
  begin
     mousestate := mouse.CurrentMouseState;
  end;



 procedure c_Input.Dispose;
 begin
   key.dispose;
   mouse.dispose;
 end;

end.
